package com.Apo1o.service.Impl;

import com.Apo1o.bean.ManagerFenceHouse;
import com.Apo1o.bean.ManagerHurdles;
import com.Apo1o.bean.ext.ManagerHurdlesExt;
import com.Apo1o.dao.Ext.ManagerHurdlesExtMapper;
import com.Apo1o.dao.ManagerFenceHouseMapper;
import com.Apo1o.exception.CustomerException;
import com.Apo1o.response.ResultCode;
import com.Apo1o.service.IHurdlesExtService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @Auther: Apo1o.
 * @Date: 2023/11/1-11-01-14:32
 * @Description： com.Apo1o.service.Impl
 */
@Service
public class HurdlesExtServiceImpl implements IHurdlesExtService {
    @Autowired
    private ManagerHurdlesExtMapper managerHurdlesExtMapper;
    @Autowired
    private ManagerFenceHouseMapper managerFenceHouseMapper;

//    @Override
//    public PageInfo<ManagerHurdlesExt> findAll() {
//        System.out.println("managerHurdlesExtMapper.findAll() = " + managerHurdlesExtMapper.findAll());
//
//        return PageInfo<>
//    }

    @Override
    public List<Integer> findAllMax() {
       return managerHurdlesExtMapper.findAllMax();
    }



    @Override
    public void deleteById(String hId) {
        if (managerHurdlesExtMapper.findById(hId) !=null) {
            managerHurdlesExtMapper.deleteById(hId);
        }else {
            throw new CustomerException(ResultCode.DATA_NOT_EXITS);
        }

    }


    @Override
    public PageInfo<ManagerHurdlesExt> selectAll(Integer pageNum, Integer pageSize, String hName, Integer hMax, String fhName, String hEnable) {
        if (pageNum==null || pageSize==null){
            throw new CustomerException(ResultCode.PARAM_NULL);
        }
        PageHelper.startPage(pageNum,pageSize);
        List<ManagerHurdlesExt> list = managerHurdlesExtMapper.findAll(hName, hMax, fhName, hEnable);
        PageInfo<ManagerHurdlesExt> page = new PageInfo<>(list);

        return page;
    }

    @Override
    public void updateEnable(String hId, String hEnable) {
        if (hEnable.equals("可用")){
            String s = "禁用";
            managerHurdlesExtMapper.updateEnable(hId,s);

        }else {
            String m = "可用";
            managerHurdlesExtMapper.updateEnable(hId,m);
        }
    }

    @Override
    public void updateEnableBatch(List<Map<String, String>> mapList) {
        mapList.forEach(e->{
          updateEnable(e.get("hId"),e.get("hEnable"));
        });
    }

    @Override
    public void deleteByIdAll(List<String> list) {
        list.forEach(this::deleteById);
    }

    @Override
    public void saveOrUpdate(ManagerHurdlesExt m) {
        if (m.getHId()!=null){
            managerHurdlesExtMapper.updateById(m);
        }else {
            String newId= UUID.randomUUID()
                    .toString()
                    .replace("-", "");
            m.setHId(newId);
            managerHurdlesExtMapper.insert(m);
        }
    }


}
